package com.system.healthproject.model.admin.controller;

import com.system.healthproject.bean.DepartmentBean;
import com.system.healthproject.bean.PagesBean;
import com.system.healthproject.bean.ResultAllHospitalDepartmentIdName;
import com.system.healthproject.bean.ResultDepartmentIdName;
import com.system.healthproject.common.ApiResult;
import com.system.healthproject.model.admin.service.DepartmentService;
import com.system.healthproject.pojo.Department;
import com.system.healthproject.pojo.Hospital;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
@Api(value = "科室管理" ,tags = "后端-医院科室接口api")
@ApiResponses({
        @ApiResponse(code=400,message="请求参数不完整或者错误"),
        @ApiResponse(code=404,message="找不到页面"),
        @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串"),
        @ApiResponse(code=500,message="后台服务错误")
})
@RequestMapping("/admin/department")
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;


    /**
     * 新增部门科室
     * @param
     * @return
     */
    @ResponseBody
    @ApiOperation(value = "新增部门科室(接口已调用)",notes = "新增部门科室",httpMethod = "post",response = ApiResult.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "hospitalId",value = "医院ID",paramType = "query",dataType = "int",required = true),
            @ApiImplicitParam(name = "departmentName",value = "科室名称",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "departmentParentid",value = "上级科室",paramType = "query",dataType = "int",required = true),
            @ApiImplicitParam(name = "departmentUser",value = "负责人",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "departmentPhone",value = "联系方式",paramType = "query",dataType = "String",required = true)
    })
    @RequestMapping(value = "/addDepartment" ,method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    public ApiResult addDepartment(Integer hospitalId,String departmentName ,Integer departmentParentid, String departmentUser,String departmentPhone  ){
            String msg = departmentService.addDepartment(hospitalId,departmentName,departmentParentid,departmentUser,departmentPhone);
        return new ApiResult(200,msg);
    }


    /**
     * 根据医院ID查询所有科室列表
     */
  @RequestMapping(value = "/selectHospitalIdDepartment" ,method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "hospitalId", value = "医院ID", paramType = "query", dataType = "int", required = true),
    })
    @ApiOperation(value = "根据医院ID查询所有科室列表(接口已调用)",notes = "查询所有",httpMethod = "post")
    public  ApiResult<PagesBean<DepartmentBean>> selectHospitalIdDepartment(Integer hospitalId,Integer page,Integer limit){
        List<DepartmentBean> list = departmentService.selectHospitalIdDepartment(hospitalId,page,limit);
        Integer count = departmentService.countDepartmentNumber(hospitalId);//根据医院ID查询统计科室数据条数
        PagesBean<DepartmentBean> pagesBean = new PagesBean<>();
        pagesBean.setData(list);
        pagesBean.setNowsPage(page);
        pagesBean.setPageSize(limit);
        pagesBean.setDataCount(count);
        return ApiResult.successWithData("",pagesBean);
    }


 /**
     * 根据医院ID查询科室ID和科室名称
     */
    @RequestMapping(value = "/selectHospitalIdName" ,method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiImplicitParam(name = "hospitalId",value = "医院ID",paramType = "query",dataType = "int",required = true)
    @ApiOperation(value = "根据医院ID查询科室ID和科室名称(接口已调用)",notes = "查询所有",httpMethod = "post")
    public  ApiResult< List<ResultDepartmentIdName>> selectHospitalIdName(Integer hospitalId){
        List<ResultDepartmentIdName> list = departmentService.selectHospitalIdName(hospitalId);

        return ApiResult.successWithData("成功",list);
    }


    /**
     * 查询所有医院ID、名称  医院对应的所有科室ID、科室名称
     */
    @RequestMapping(value = "/selectAllHospitalDepartmentIdName" ,method = RequestMethod.GET,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiOperation(value = "查询所有医院ID、名称  医院对应的所有科室ID、科室名称(接口已调用)",notes = "查询所有",httpMethod = "post")
    public  ApiResult< List<ResultAllHospitalDepartmentIdName>> selectAllHospitalDepartmentIdName(){
        List<ResultAllHospitalDepartmentIdName> list = departmentService.selectAllHospitalDepartmentIdName();
        return ApiResult.successWithData("成功",list);
    }

    /**
     * 修改科室信息
     */
    @RequestMapping(value = "/updateDepartment" ,method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "hospitalId",value = "医院ID",paramType = "query",dataType = "int",required = true),
            @ApiImplicitParam(name = "departmentId",value = "科室ID",paramType = "query",dataType = "int",required = true),
            @ApiImplicitParam(name = "departmentName",value = "科室名称",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "departmentParentid",value = "上级科室",paramType = "query",dataType = "int",required = false),
            @ApiImplicitParam(name = "departmentUser",value = "负责人",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "departmentPhone",value = "联系方式",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "createTime",value = "科室创建时间",paramType = "query",dataType = "String",required = false)
    })
    @ApiOperation(value = "修改科室信息(接口已调用)",notes = "修改科室信息",httpMethod = "post",response = ApiResult.class)
    public  ApiResult updateDepartment(Integer hospitalId,Integer departmentId,String departmentName ,String createTime,
                                       Integer departmentParentid, String departmentUser,String departmentPhone){
            String msg = departmentService.updateDepartment(hospitalId,departmentId,departmentName,departmentParentid,departmentUser,departmentPhone, createTime);
        return ApiResult.successWithData(msg);
    }


    /**
     * 根据医院ID和科室ID查询科室详细信息
     */
    @RequestMapping(value = "/selectHospitalIdDepartmentId" ,method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "hospitalId", value = "医院ID", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "departmentId", value = "科室ID", paramType = "query", dataType = "int", required = true),
    })
    @ApiOperation(value = "根据医院ID和科室ID查询科室详细信息(接口已调用)",notes = "查询所有",httpMethod = "post")
    public  ApiResult<Department> selectHospitalIdDepartmentId(Integer hospitalId,Integer departmentId){
        Department department= departmentService.selectHospitalIdDepartmentId(hospitalId,departmentId);

        return ApiResult.successWithData("成功",department);
    }


    /**
     * 根据科室ID删除科室
     */
    @RequestMapping(value = "/deleteDepartment" ,method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "departmentId", value = "科室ID", paramType = "query", dataType = "int", required = true),
    })
    @ApiOperation(value = "根据科室ID删除科室(接口已调用)",notes = "查询所有",httpMethod = "post")
    public  ApiResult<Department> deleteDepartment(Integer departmentId){
        String msg= departmentService.deleteDepartment(departmentId);
        return ApiResult.success(msg);
    }


}
